﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

// Reviewed

#pragma once
#include "GcmpGeometryInterface.h"

#include "Vector3d.h"
#include "Intervald.h"
#include "CurveCurveIntersectTypes.h"
#include "CurveSurfaceIntersectTypes.h"
#include "SurfaceSurfaceIntersectTypes.h"
#include "ICurve2dCoincidenceData.h"
#include "ICurve3dCoincidenceData.h"
#include "ICurveSurfaceCoincidenceData.h"
#include "ICurve2dCurve2dIntersection.h"
#include "ICurve3dCurve3dIntersection.h"
#include "ICurve3dSurfaceIntersection.h"
#include "ISurfaceSurfaceIntersection.h"
#include "GcmpApiDeclaration.h"

namespace gcmp
{
    class ICurve2d;
    class ISurface;
    class ILine3d;
    class IPlane;
    class IPolygon;
    class IFace;
    class IMesh;
    class IBody;
    class ICurveBodyIntersection;

    class IIntersect
    {
    public:
        virtual ~IIntersect() = 0;

         /// \brief 三维曲线和几何曲面求交
         /// \param const ICurve3d *pGmICurve3d         三维曲线
         /// \param const ISurface *pGmISurface       几何曲面
         /// \param std::vector<OwnerPtr<CurvSurfInt>> &pIntersects       求交结果（自定义结构体）
         /// \return bool 是否相交
        virtual bool Intersect(const ICurve3d *pGmICurve3d, const ISurface *pGmISurface, std::vector<OwnerPtr<ICurve3dSurfaceIntersection>> &opIntersects, double dDistanceEpsilon) const = 0;

         /// \brief 两个几何曲面求交
         /// \param const ISurface *pFirGmISurface         第一个几何曲面
         /// \param const ISurface *pSecGmISurface       第二个几何曲面
         /// \param trimIntersectCurveOutOfSurfaceDomain 对交线超出曲面参数域的部分进行裁剪
         /// \param std::vector<OwnerPtr<SurfSurfInt>> &pIntersects       求交结果（自定义结构体）
         /// \return bool 是否相交
        virtual bool Intersect(const ISurface *pFirGmISurface, const ISurface *pSecGmISurface,bool trimIntersectCurveOutOfSurfaceDomain, std::vector<OwnerPtr<ISurfaceSurfaceIntersection>> &opIntersects, double dDistanceEpsilon) const = 0;

         /// \brief 二维曲线与Polygon求交（求二维曲线在Polygon内部的部分）
         /// \param const ICurve2d *pCurve                        二维曲线
         /// \param const IPolygon *pPolygon                       Polygon
         /// \param bool getIfCurveOnPolygon                        如果pCurve和Polygon的某条边重合，重合的部分要不要返回，true返回，false不返回
         /// \param std::vector<Intervald> &pIntersects            求交结果（自定义结构体）Intervald
         /// \return bool 是否相交
        virtual bool Intersect(const ICurve2d *pCurve, const IPolygon *pPolygon, bool getIfCurveOnPolygon,std::vector<Intervald>& opIntersects, double dDistanceEpsilon) const = 0;

        /// \brief 两条二维曲线求交
        /// \param const ICurve2d *pFirGmICurve2d         第一条二维曲线
        /// \param const ICurve2d *pSecGmICurve2d       第二条二维曲线
        /// \param std::vector<OwnerPtr<Curve2dInt>> &pIntersects         求交结果（自定义结构体）
        /// \param double dDistanceEpsilon                距离容差,数值大小可参照Constants::DISTANCE_ITERATION_EPS=1e-4
        /// \return bool 是否相交
        virtual bool Intersect(const ICurve2d *pFirGmICurve2d, const ICurve2d *pSecGmICurve2d, std::vector<OwnerPtr<ICurve2dCurve2dIntersection>> &opIntersects, double dDistanceEpsilon) const = 0;

        /// \brief 两条三维曲线求交
        /// \param const ICurve2d *pFirGmICurve2d         第一条三维曲线
        /// \param const ICurve2d *pSecGmICurve2d       第二条三维曲线
        /// \param std::vector<OwnerPtr<Curve3dInt>> &pIntersects         求交结果（自定义结构体）
        /// \param double dDistanceEpsilon                距离容差,数值大小可参照Constants::DISTANCE_ITERATION_EPS=1e-4
        /// \return bool 是否相交
        virtual bool Intersect(const ICurve3d *pFirGmICurve3d, const ICurve3d *pSecGmICurve3d, std::vector<OwnerPtr<ICurve3dCurve3dIntersection>> &opIntersects, double dDistanceEpsilon) const = 0;

        /// \brief 两条三维曲线延伸求交,
        /// \param const ICurve2d *pFirGmICurve2d         第一条三维曲线
        /// \param const ICurve2d *pSecGmICurve2d         第二条三维曲线
        /// \param std::vector<OwnerPtr<Curve3dInt>> &pIntersects         求交结果（自定义结构体）
        /// \param double dDistanceEpsilon                距离容差,数值大小可参照Constants::DISTANCE_ITERATION_EPS=1e-4
        /// \return bool 是否相交
        virtual bool IntersectByExtend(const ICurve3d *pFirGmICurve3d, const ICurve3d *pSecGmICurve3d, std::vector<OwnerPtr<ICurve3dCurve3dIntersection>> &opIntersects, double dDistanceEpsilon) const = 0;

        /// \brief 计算拓扑面和三维曲线的交点, 只有一个交点时使用（交点为Face上的点, 如有返回在Curve3d上点的需求请联系文件的Owner）
        /// \param const IFace* pGmFace            拓扑面
        /// \param const ICurve3d* pGmICurve3d    三维曲线
        /// \param constVector3d &minDisPtOnFace   拓扑面上的点
        /// \param int& iRealIntersect             Edge参与-2/平行-1/默认0/内部1/边界2/
        /// \param double disTolerance              容差,数值大小可参照Constants::DISTANCE_ITERATION_EPS=1e-4
        /// \return    最小距离是否满足精度要求
        virtual bool Intersect(const IFace* pGmFace, const ICurve3d* pGmICurve3d, Vector3d &minDisPtOnFace, int& iRealIntersect, double disTolerance)const = 0;

        /// \brief 计算直线和Mesh的交点, 可以有多个交点，交点按照在直线上的深度排序
        /// \param const ILine3d* pLine           三维直线
        /// \param const IMesh* pMesh             三角面片集合
        /// \param std::vector<Vector3d>& intersectPoints   交点集合
        /// \param std::vector<std::vector<Vector3d>>& intersectTriangles   相交的三角面片集合
        /// \return 直线和Mesh是否相交
        virtual bool Intersect(const ILine3d* pLine, const IMesh* pMesh, std::vector<Vector3d>& intersectPoints, std::vector<std::vector<Vector3d>>& intersectTriangles) const = 0;
    
        /// \brief 计算三维曲线和体外壳的所有交点并按交点参数值升序排序，重合段记录起始点和终止点
        /// \param[in] pCurve                           三维曲线,不能为空,否则报错
        /// \param[in] pBody                            体,不能为空,否则报错
        /// \param[in] distanceEpsilon                  容差,数值大小可参照Constants::DISTANCE_ITERATION_EPS=1e-4
        /// \param[out] intersects                      交点集合(按在曲线上参数升序排列),不能为空,否则报错
        /// \return 曲线和体是否有交点,true有,false没有
        virtual bool Intersect(const ICurve3d* pCurve, const IBody* pBody, double distanceEpsilon, std::vector<OwnerPtr<ICurveBodyIntersection>> &intersects) const = 0;
      
        /// \brief 两个几何曲面求交
        ///
        /// \param pFirstSurface         第一个几何曲面
        /// \param pSecondSurface        第二个几何曲面
        /// \param opIntersects          求交结果
        /// \param distanceEpsilon       距离容差
        /// \return 相交返回true，不相交返回false
        GCMP_OBSOLETE_API(2020 / 5 / 9, IIntersect::Intersect(const ISurface*, const ISurface*, bool, std::vector<OwnerPtr<ISurfaceSurfaceIntersection>>&, double)) virtual bool Intersect(const ISurface *pFirstSurface, const ISurface *pSecondSurface, std::vector<OwnerPtr<ISurfaceSurfaceIntersection>> &opIntersects, double distanceEpsilon)const=0;

    
    };

    inline IIntersect::~IIntersect() {}

}
